package thread;

public class FinalField {
    final int x;
    int y;
    static FinalField f;

    public FinalField() throws Exception{
        x = 3;
        y = 4;
    }

    static void writer()throws Exception {
        f = new FinalField();
    }

    static void reader() {
        if (f != null&&f.y==0) {
            System.out.println(f.y);
        }
    }

    public static void main(String[] args) {

        Thread t1 = new Thread(()->{
            try {
                writer();
            } catch (Exception e) {
                e.printStackTrace();
            }
        });

        for (int i = 0; i < 100; i++) {
            Thread t2 = new Thread(()->{
                reader();
            });

            t2.start();
            if (i == 30) {
                t1.start();
            }
        }




    }
}
